using SALSA
using Base.Test

X = linspace(0,1,10)'

(w,b) = pegasos_alg(loss_derivative(HINGE),[X;X],[-1,-1],1.0,2,1000,1e-5)

w_ref = [0.0
 -0.02460782639290451
 -0.04921565278580902
 -0.07382347917871344
 -0.09843130557161804
 -0.1230391319645226
 -0.1476469583574269
 -0.17225478475033157
 -0.19686261114323608
 -0.22147043753614062]

@test_approx_eq_eps w w_ref 1e-5
@test_approx_eq_eps b -0.22147043753614062 1e-5

(w,b) = pegasos_alg(loss_derivative(HINGE),[X;X],[-1,-1],1.0,1,1000,1e-5,true)

w_ref = [0.0
 -0.02613541867446583
 -0.05227083734893166
 -0.07840625602339749
 -0.10454167469786332
 -0.13067709337232916
 -0.15681251204679497
 -0.18294793072126084
 -0.20908334939572665
 -0.23521876807019249]

@test_approx_eq_eps w w_ref 1e-5
@test_approx_eq_eps b -0.23521876807019249 1e-5

(w,b) = pegasos_alg(loss_derivative(HINGE),[X;X],[-1,-1],1.0,1,1000,1e-5,true,[1])

w_ref = [0.0
 -0.05227083734893166
 -0.10454167469786332
 -0.15681251204679497
 -0.20908334939572665
 -0.2613541867446583
 -0.31362502409358994
 -0.3658958614425217
 -0.4181666987914533
 -0.47043753614038497]

@test_approx_eq_eps w w_ref 1e-5
@test_approx_eq_eps b -0.47043753614038497 1e-5

(w,b) = pegasos_alg(loss_derivative(PINBALL,0.01),[X;X],[-1,-1],1.0,2,1000,1e-5)

w_ref = [0.0
 -0.02464115972623781
 -0.04928231945247562
 -0.07392347917871346
 -0.09856463890495124
 -0.12320579863118898
 -0.14784695835742692
 -0.17248811808366468
 -0.19712927780990247
 -0.22177043753614048]

@test_approx_eq_eps w w_ref 1e-5
@test_approx_eq_eps b -0.22177043753614048 1e-5

(w,b) = pegasos_alg(loss_derivative(HINGE),sparse([X 0 0;X 0 0]),[-1,-1],1.0,2,1000,1e-5)

w_ref = sparse([
  0.0
 -0.02460782639290451
 -0.04921565278580902
 -0.07382347917871344
 -0.09843130557161804
 -0.1230391319645226
 -0.1476469583574269
 -0.17225478475033157
 -0.19686261114323608
 -0.22147043753614062
  0.0
  0.0])

@test_approx_eq_eps w w_ref 1e-5
@test_approx_eq_eps b -0.22147043753614062 1e-5

(w,b) = pegasos_alg(loss_derivative(PINBALL,0.01),sparse([X 0 0;X 0 0]),[-1,-1],1.0,2,1000,1e-5)

w_ref = sparse([
  0.0
 -0.02464115972623781
 -0.04928231945247562
 -0.07392347917871346
 -0.09856463890495124
 -0.12320579863118898
 -0.14784695835742692
 -0.17248811808366468
 -0.19712927780990247
 -0.22177043753614048
  0.0
  0.0])

@test_approx_eq_eps w w_ref 1e-5
@test_approx_eq_eps b -0.22177043753614012 1e-5